var pageii = null;
var grid = null;
$(function() {
	grid = lyGrid({
		id : 'paging',
		l_column : [ {
			colkey : "id",
			name : "id",
			hide:true
		}, {
			colkey : "userName",
			name : "姓名"
		},{
			colkey : "phone",
			name : "注册手机"
		},{
			colkey : "userAddr",
			name : "地址"
		},   {
			colkey : "createTime",
			name : "注册时间",
			width : '160px',
			renderData : function(rowindex,data, rowdata, column) {
				return new Date(data).format("yyyy-MM-dd hh:mm:ss");
			}
		} ],
		jsonUrl : rootPath + '/resident/findByPage.shtml',
		checkbox : false,
		serNumber : true
	});
	$("#search").click("click", function() {// 绑定查询按扭
		var searchParams = $("#searchForm").serializeJson();// 初始化传参数
		grid.setOptions({
			data : searchParams
		});
	});
	$("#addResident").click("click", function() {
		addResident();
	});
	$("#editResident").click("click", function() {
		editResident();
	});
	$("#delResident").click("click", function() {
		delResident();
	});
	$("#handsel").click("click", function() {
		handsel();
	});
	$("#integralList").click("click", function() {
		integralList();
	});
});
function checkstate(obj,id){
	var d = 'N';
	if(obj.checked){
		d = 'Y';
	}
	var url = rootPath + '/resident/updateState.shtml';
	var s = CommnUtil.ajax(url, {
		"residentFormMap.id" : id,
		"residentFormMap.isAuth" : d
	}, "json");
	if (s == "success") {
		layer.msg('操作成功');
	} else {
		layer.msg('操作失败');
	}
}
function checkMaster(obj,id){
	var d = 'N';
	if(obj.checked){
		d = 'Y';
	}
	var url = rootPath + '/resident/updateMaster.shtml';
	var s = CommnUtil.ajax(url, {
		"residentFormMap.id" : id,
		"residentFormMap.isMaster" : d
	}, "json");
	if (s == "success") {
		layer.msg('操作成功');
	} else {
		layer.msg('操作失败');
	}
}
function editResident() {
	var cbox = grid.getSelectedCheckbox();
	if (cbox.length > 1 || cbox == "") {
		layer.msg("只能选中一个");
		return;
	}
	var url = rootPath + '/resident/editUI.shtml?id=' + cbox;
	pageii = layer.open({
		title : "编辑",
		type : 1,
		area : [ "600px", "80%" ],
		content : CommnUtil.ajax(url)
	});
}
function handsel() {
	var cbox = grid.getSelectedCheckbox();
	if (cbox.length > 1 || cbox == "") {
		layer.msg("只能选中一个");
		return;
	}
	var url = rootPath + '/resident/handselUI.shtml?id=' + cbox;
	pageii = layer.open({
		title : "积分赠送",
		type : 1,
		area : [ "600px", "80%" ],
		content : CommnUtil.ajax(url)
	});
}
function integralList() {
	var cbox = grid.getSelectedCheckbox();
	if (cbox.length > 1 || cbox == "") {
		layer.msg("只能选中一个");
		return;
	}
	var url = rootPath + '/resident/integralListUI.shtml?id=' + cbox;
	pageii = layer.open({
		title : "积分明细",
		type : 1,
		area : [ "600px", "80%" ],
		content : CommnUtil.ajax(url)
	});
}
function addResident() {
	var url =rootPath + '/resident/addUI.shtml';
	pageii = layer.open({
		title : "新增",
		type : 1,
		area : [ "600px", "80%" ],
		content : CommnUtil.ajax(url)
	});
}
function delResident() {
	var cbox = grid.getSelectedCheckbox();
	if (cbox == "") {
		layer.msg("请选择删除项！！");
		return;
	}
	layer.confirm('是否删除？', function(index) {
		var url = rootPath + '/resident/deleteEntity.shtml';
		var s = CommnUtil.ajax(url, {
			ids : cbox.join(",")
		}, "json");
		if (s == "success") {
			layer.msg('删除成功');
			grid.loadData();
		} else {
			layer.msg('删除失败');
		}
	});
}